<template>
  <div class="consultation">
    <div class="consultation-block">
      <div class="table" v-loading="tableLoading">
        <el-table size="mini" :data="tableData" style="width: 100%">
          <el-table-column prop="no" label="报销编号"> </el-table-column>
          <el-table-column prop="hyrName" label="核验人姓名"> </el-table-column>
          <el-table-column prop="hyrPhone" label="核验人手机号"> </el-table-column>
          <el-table-column prop="bankCardUserName" label="报销者开户姓名"> </el-table-column>
          <el-table-column prop="bankCardNo" label="报销者卡号"> </el-table-column>
          <el-table-column prop="createTime" label="报销提交日期"> </el-table-column>
          <el-table-column label="操作" width="150">
            <template slot-scope="scope">
            <div style="display: flex;gap:20px;">
              <el-button
                type="warning"
                size="mini"
                v-if="scope.row.status === '已核验'"
                @click="doBX(scope.row)"
                >报销</el-button
              >
              <div v-if="scope.row.status !== '已核验'">
                {{ scope.row.status }}
              </div>

              <el-button
                type="danger"
                size="mini"
                @click="doDelete(scope.row)"
                >删除</el-button
              >
            </div>
              
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="pagination">
        <el-pagination
          background
          layout="prev, pager, next"
          :current-page.sync="currentPage"
          @current-change="handleCurrentChange"
          :page-size="pageSize"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import moment from 'moment';
import { getExpense, updateExpense, deleteExpense } from "../service.js";
export default {
  name: "home",
  mounted() {
    this.refreshTable();
  },
  data() {
    return {
      tableData: [],
      currentPage: 1,
      filterKey: '',
      isInsert: false,
      pageSize: 10,
      total: 0,
      tableLoading: false,
    };
  },
  methods: {
    handleCurrentChange(index) {
      this.currentPage = index
      this.refreshTable()
    },
    refreshTable() {
      getExpense({
        page: this.currentPage,
        pageSize: this.pageSize,
      }).then((res) => {
        this.tableData = res.code === 200 ? res.data.data : [];
        this.total = res.data.total
      });
    },
    doBX(row) {
      updateExpense(row.id, {
        status: '已报销'
      }).then(res => {
        this.$message.success('报销成功')
        this.refreshTable()
      })
    },
    doDelete(row) {
      this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteExpense(row.id).then(res => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.refreshTable()
          })
        })
    }
  },
};
</script>

<style scoped>
h2 {
  text-align: center;
  margin-top: 20px;
  margin-bottom: 20px;
}
.consultation-block {
  width: 90%;
  margin-left: 5%;
}

.pagination {
  text-align: center;
  margin-top: 20px;
}
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 60px;
  height: 60px;
  line-height: 60px;
  border: 1px dashed gray;
  text-align: center;
}
.avatar {
  width: 60px;
  height: 60px;
  display: block;
}
.img-blocks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.el-icon-circle-close {
  position: absolute;
  top: -5px;
  right: -5px;
  cursor: pointer;
  color: red;
}
</style>
